package com.ysdz.tibetan.tibetanmini.product.controller;

import com.ysdz.tibetan.tibetanmini.product.service.ProductService;
import com.ysdz.tibetan.tibetanminicommons.common.ReturnMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(value = "实现商品相关操作", tags = "商品相关接口")
@RequestMapping("/pro")
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/getpro/{proId}")
    public ReturnMsg getProductById(@PathVariable("proId") String id){
        return productService.selectProductById(id);
    }

    @ApiOperation("分页查询商品接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "keyword", value = "查询关键词", required = true),
            @ApiImplicitParam(dataType = "int", name = "pagenum", value = "查询页数", required = true),
            @ApiImplicitParam(dataType = "int", name = "pagesize", value = "查询每页数量", required = true)
    })
    @GetMapping("/search/{keyword}/{pagenum}/{pagesize}")
    public ReturnMsg searchPaging(@PathVariable("keyword") String keyword,
                            @PathVariable("pagenum") Integer pagenum,
                            @PathVariable("pagesize") Integer pagesize){
        if (pagenum == null) pagenum = 1;
        return productService.selectProductsByKeywordByPaging(keyword, "0", pagenum, pagesize);
    }

    @ApiOperation("关键词查询商品接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "keyword", value = "查询关键词", required = true),
    })
    @GetMapping("/search/{keyword}")
    public ReturnMsg search(@PathVariable("keyword") String keyword){
        return productService.selectProductsByKeyword(keyword);
    }
}
